package com.zzy.controller;

import com.zzy.domain.dto.WarehouseAreaPageDto;
import com.zzy.domain.Result;
import com.zzy.domain.po.WarehouseArea;
import com.zzy.service.WarehouseAreaService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/warehouseArea")
public class WarehouseAreaController  {
    private final WarehouseAreaService warehouseAreaService;
    /**
     * 分页查询
     */

    @GetMapping("/areaPage")
    public Result page(WarehouseAreaPageDto dto){
        return Result.success(warehouseAreaService.getPage(dto));
    }
    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody  WarehouseArea warehouseArea){
        warehouseArea.setCreateTime(LocalDateTime.now());
        return Result.success(warehouseAreaService.save(warehouseArea));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    public Result update(@RequestBody WarehouseArea warehouseArea){

        return Result.success(warehouseAreaService.updateById(warehouseArea));
    }
    /**
     * 删除
     */

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Long>ids){
        return Result.success(warehouseAreaService.removeBatchById(ids));
    }
}
